<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 数组
        let arr = [2, 6, 1, 7, 4]

        let sun = 0
        // 遍历循环 i=0是因为数据是从0开始的,退出条件是数组长度大于i
        for (let i = 0; i < arr.length; i++) {
            // 这里开始循环sun/现在sun等于数组总和
            sun = arr[i] + sun
            // arr[i]是数组按顺序计算加

        }
        let pjun = sun / arr.length
        document.write(sun)
        console.log(pjun)
    </script>
</body>

</html>